package com.njzxw.fs.commonutil.imp;

import com.njzxw.fs.commonutil.bean.Common;
import com.njzxw.fs.commonutil.bean.FileBean;
import com.njzxw.fs.commonutil.bean.PartBean;
import com.njzxw.fs.commonutil.interfaces.OssUtilInterface;
import com.njzxw.fs.commonutil.util.VerifyCodeUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.Random;

public abstract class OssUtilAbs implements OssUtilInterface {

    public org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    protected Common common;

    @Autowired
    protected VerifyCodeUtils verifyCodeUtils;

    @Override
    public FileBean saveTemp(MultipartFile multipartFile, String name, long size, String md5) {
        return null;
    }

    @Override
    public FileBean saveTemp(MultipartFile multipartFile, String name, long size) {
        return null;
    }

    @Override
    public FileBean saveTemp(InputStream inputStream, String name, long size) {
        return null;
    }

    @Override
    public FileBean saveTemp(InputStream inputStream, String name, long size, String md5) {
        return null;
    }

    public FileBean exeName(String name, long size) {
        //wxd0d748bb78db8b93.o6zAJs5_AZN9IOUA_US8X23qqLQs.WyOKeVVC34Yje5f770aa584ec22f8eda46d1d8672be7.png
        String[] names = name.split("\\.");
        if (names.length < 2) {
            return null;
        }
        FileBean fileBean = new FileBean();

        String name_qz = verifyCodeUtils.generateVerifyCode(8) + new Random().nextInt(1000000);

        String file_name = (name_qz + "_" + new Random().nextInt(100000000)) + "." + names[names.length - 1];
        if (file_name.startsWith("/")) {
            file_name = file_name.substring(1);
        }
        fileBean.setOriginal_file_name(name);
        fileBean.setFile_name(file_name);
        fileBean.setType(names[names.length - 1].toLowerCase());
        fileBean.setSize(String.valueOf(size));
        String temp_host = common.getSystem("RESOURCE.TEMP.IMGHOST");

        temp_host += common.getSystem("RESOURCE.TEMP.PATH");

//        System.out.println(temp_host);

        fileBean.setImg_host(temp_host);
        fileBean.setPath(common.getSystem("RESOURCE.TEMP.PATH"));

        return fileBean;
    }

    @Override
    public void createPart(PartBean partBean) throws Exception {

    }

    @Override
    public void uploadPart(PartBean partBean) throws Exception {

    }

    @Override
    public void closePart(PartBean partBean) throws Exception {

    }
}
